package cn.supermaster.management.web.rest.system;

import cn.supermaster.management.common.annotation.Log;
import cn.supermaster.management.common.domain.SystemUser;
import cn.supermaster.management.common.enums.BusinessType;
import cn.supermaster.management.common.page.TableDataInfo;
import cn.supermaster.management.common.response.WebResponse;
import cn.supermaster.management.web.service.system.ISUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: supermaster-management
 * @Package: cn.supermaster.management.web.rest.system
 * @ClassName: SystemUserRestController
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021/1/11 2:43
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.comn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Api("用户信息管理")
@RequestMapping("/system/user")
@RestController
public class SystemUserRestController {

    @Autowired
    private ISUserService userService;

    @ApiOperation("根据条件获取用户列表")
    @RequiresPermissions("system:user:list")
    @PostMapping("/list")
    public TableDataInfo queryUserListByCondition(SystemUser user) {
        return userService.queryUserListByCondition(user);
    }

    @ApiOperation("导出用户列表")
    @Log(title = "用户管理", businessType = BusinessType.EXPORT)
    @RequiresPermissions("system:user:export")
    @PostMapping("/export")
    public WebResponse doExportUserInformation(SystemUser user) {
        return userService.doExportUserInformation(user);
    }

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @RequiresPermissions("system:user:import")
    @PostMapping("/importData")
    public WebResponse doImportUserInformation(MultipartFile file, boolean updateSupport) {
        return userService.doImportUserInformation(file, updateSupport);
    }

    @RequiresPermissions("system:user:view")
    @GetMapping("/importTemplate")
    public WebResponse doImportUserTemplate() {
        return userService.doImportUserTemplate();
    }

    /**
     * 新增保存用户
     */
    @RequiresPermissions("system:user:add")
    @Log(title = "用户管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public WebResponse doAddUserInformation(@Validated SystemUser user) {
        return userService.doAddUserInformation(user);
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("system:user:edit")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public WebResponse doModifyUserInformation(@Validated SystemUser user) {
        return userService.doModifyUserInformation(user);
    }

    @RequiresPermissions("system:user:resetPwd")
    @Log(title = "重置密码", businessType = BusinessType.UPDATE)
    @PostMapping("/resetPwd")
    public WebResponse doResetPassword(SystemUser user) {
        return userService.doResetPassword(user);
    }

    /**
     * 用户授权角色
     */
    @RequiresPermissions("system:user:add")
    @Log(title = "用户管理", businessType = BusinessType.GRANT)
    @PostMapping("/authRole/insertAuthRole")
    public WebResponse doInsertAuthRole(Long userId, Long[] roleIds) {
        return userService.doInsertAuthRole(userId, roleIds);
    }

    // 删除用户信息
    @RequiresPermissions("system:user:remove")
    @Log(title = "用户管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public WebResponse doRemoveUserInformation(String ids) {
        return userService.doRemoveUserInformation(ids);
    }

    /**
     * 校验用户名
     */
    @PostMapping("/checkuserNameUnique")
    public String doCheckuserNameUnique(SystemUser user) {
        return userService.doCheckuserNameUnique(user);
    }

    /**
     * 校验手机号码
     */
    @PostMapping("/checkPhoneUnique")
    public String doCheckMobileUnique(SystemUser user) {
        return userService.doCheckMobileUnique(user);
    }

    /**
     * 校验email邮箱
     */
    @PostMapping("/checkEmailUnique")
    public String doCheckEmailUnique(SystemUser user) {
        return userService.doCheckEmailUnique(user);
    }

    /**
     * 用户状态修改
     */
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("system:user:edit")
    @PostMapping("/changeStatus")
    public WebResponse doChangeUserStatus(SystemUser user) {
        return userService.doChangeUserStatus(user);
    }
}